/*
 * Copyright 2009 Tran Nhut Trung.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package com.gdevelop.gwtxp.rebind.gwt;


import com.gdevelop.gwtxp.rebind.Tag;

import com.google.gwt.user.client.ui.FlexTable;


public class FlexTableTag extends HTMLTableTag{
  public FlexTableTag() {
  }

  public Class getUIClass() {
    return FlexTable.class;
  }

  public void generateAddUI(Tag child) {
    // No-op, the TableCellTag handle the adding
  }
  
  public void generateSetCellAttibutes(TableCellTag cellTag, Tag child){
    String row = cellTag.getAttribute("row");
    String col = cellTag.getAttribute("col");
    if ((row == null) || (col == null)){
      throw new RuntimeException("TableCell must have row and col attribute.");
    }

    if (FlexTable.class.isAssignableFrom(this.getUIClass())){
      String rowSpan = cellTag.getAttribute("rowSpan");
      String colSpan = cellTag.getAttribute("colSpan");
      if (rowSpan != null){
        out.println(this.getVarName() + ".getFlexCellFormatter().setRowSpan(" + row + ", " + col + ", " + rowSpan + ");");
      }
      if (colSpan != null){
        out.println(this.getVarName() + ".getFlexCellFormatter().setColSpan(" + row + ", " + col + ", " + colSpan + ");");
      }
    }
    
    super.generateSetCellAttibutes(cellTag, child);
  }
}
